package com.bw.good

import com.alibaba.android.arouter.facade.annotation.Autowired
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bawei.base.RoutePath
import com.bawei.common.mvi.BaseMviActivity
import com.bawei.good.R
import com.bawei.good.databinding.ActivityGoodDetailBinding
import com.bawei.image.LoadImageUtil
import com.bw.good.adapter.BannerGoodAdapter
import com.bw.good.entity.GoodEntity
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RoutePath.PATH_GOOD_DETAIL_PAGE)
@AndroidEntryPoint
class GoodDetailActivity : BaseMviActivity<ActivityGoodDetailBinding>() {

    @Autowired lateinit var entity: GoodEntity

    private lateinit var mBannerGoodAdapter: BannerGoodAdapter

    override fun getLayoutId(): Int = R.layout.activity_good_detail

    override fun initViews() {

        ARouter.getInstance().inject(this)

        //设置返回按钮点击事件
        mDataBinding.ivBack.setOnClickListener {
            //点击返回列表
            this@GoodDetailActivity.finish()
        }

        //设置轮播图
        mBannerGoodAdapter = BannerGoodAdapter(entity.bannerList)
        mDataBinding.icGoodBanner.setAdapter(mBannerGoodAdapter)

        //商品价格
        mDataBinding.tvPrice.text = "￥${entity.goods_default_price}"
        mDataBinding.tvPrice1.text = "￥${entity.goods_default_price + 1000}"
        //商品描述
        mDataBinding.tvDesc.text = entity.goods_desc
        //商品地址
        mDataBinding.tvDizhi.text = "深圳市"
        //商品已售数量
        mDataBinding.tvYs.text = "已售${entity.goods_sales_count}"
        //商品详情图
        LoadImageUtil.loadUrl(this,entity.goods_detail_one,mDataBinding.ivGoodIcon1)
        LoadImageUtil.loadUrl(this,entity.goods_detail_two,mDataBinding.ivGoodIcon2)

        //点击跳转到购物车
        mDataBinding.ivCar.setOnClickListener {

        }

        //点击分享
        mDataBinding.ivFenxiang.setOnClickListener {

        }

        //点击跳转到评论页面
        mDataBinding.tvPingJia.setOnClickListener {
            showToastMsg("评论系统维护中，请稍后再来")
        }

        //点击跳转到客服页面
        mDataBinding.ivKefu.setOnClickListener {
            showToastMsg("人工客服繁忙，请稍后联系！")
        }

        //点击加入购物车
        mDataBinding.tvAddCar.setOnClickListener {

        }
        //立即购买商品
        mDataBinding.tvJs.setOnClickListener {
            ARouter.getInstance().build(RoutePath.PATH_GOOD_BUG_PAGE).withSerializable("goodEntity", entity).navigation()
            this@GoodDetailActivity.finish()
        }
    }

}